<template>
<div id="video">
  <div class="video-container" :class="{'show': showVideo}">
    <video v-if="!showVideo" @click="showOrHideVideo()" :src="videoUrl" loop preload autoplay></video>
    <video class="big" :src="videoUrl" preload autoplay loop v-else></video>
    <span class="close" v-show="showVideo" @click="showOrHideVideo(1)"><i class="iconfont ico-close"></i></span>
  </div>
</div>
</template>

<script>
import { queryVideoPath } from '../common/api'

export default {
  data() {
    return {
      videoUrl: '',
      showVideo: false
    }
  },
  created() {
    // 页面加载完成，渲染页面
    this.$nextTick(() => {
    })
    this.getVideoPath()
  },
  methods: {
    /**
     * 展示或隐藏视频
     *
     * @param { Boolean } isClose 是否是关闭
     */
    showOrHideVideo(isClose) {
      if (isClose == 1) {
        this.showVideo = false
        this.$emit('shade', this.showVideo)
        return
      }
      this.showVideo = true
      this.$emit('shade', this.showVideo)
    },
    getVideoPath() {
      queryVideoPath().then(data => {
        this.videoUrl = data.path
      })
    }
  }
}
</script>

<style lang="scss" scoped>
#video {
  position: relative;
  margin: 0 auto;

  .video-container{
    bottom: 0px;
    position: relative;
    top: 0px;
    left: 0px;
    right: 0px;
    width: 1230px;
    margin: 0 auto;
    height: 100%;
    z-index: 60;

    video {
      display: block;
      width: 220px;
      bottom: 28px;
      position: absolute;
      right: 0px;
      background: #000;
      &.big {
        position: fixed;
        top: calc(50% - 300px);
        left: calc(50% - 533px);
        width: 1066px;
        height: 600px;
      }
    }

    .close {
      background-color: #1b1b1b;
      border-radius: 20px;
      border: 4px solid #ffffff;
      color: #ffffff;
      cursor: pointer;
      display: block;
      width: 40px;
      height: 40px;
      line-height: 32px;
      text-align: center;
      top: calc(50% - 320px);
      right: calc(50% - 553px);
      position: fixed;
    }
  }
}
</style>